//
//  PredeteViewController.m
//  TravelFollowYourHeart
//
//  Created by ENERGY on 2017/12/21.
//  Copyright © 2017年 Lwx. All rights reserved.
//

#import "PredetermineViewController.h"
#import "PredetermineViewCell.h"
#import "OrderInformationViewController.h"
#import "PredetermineModel.h"
#import "ImmediateEvaluationViewController.h"
#import "ActivityDetailViewController.h"

@interface PredetermineViewController ()<UITableViewDelegate, UITableViewDataSource, PredeterminViewCellDelegate>
@property (nonatomic, strong)UITableView * tableView;
@property (nonatomic, strong)PredetermineModel * model;
@end

@implementation PredetermineViewController (Networking)
- (void)getMyOrderList{
    NSDictionary * dic = @{
                           @"mid":[UserModel intance].member_id,
                           @"token":[UserModel intance].token
                           };
    WS(ws)
    [[HUDHelper sharedInstance]syncLoading:@"翻箱中..."];
    [[HttpRequest shardWebUtil] postNetworkRequestURLString:Url(@"/member/myOrders") andParas:dic andTransferGottenData:^(id obj, NSError *error) {
        [[HUDHelper sharedInstance]syncStopLoading];
        if (error)
        {
            [[HUDHelper sharedInstance]tipMessage:obj[@"msg"]];
        }
        else
        {
            if ([obj[@"code"] integerValue] == 100000)
            {
                ws.model = [PredetermineModel yy_modelWithDictionary:obj];
                [self.tableView reloadData];
            }
            else
            {
                [[HUDHelper sharedInstance]tipMessage:obj[@"msg"]];
            }
        }
    }];
}
@end

@implementation PredetermineViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"我的预定";
    [self.view addSubview:self.tableView];
    [self getMyOrderList];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - 64)];
        _tableView.backgroundColor = getColor(bgColor);
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    }return _tableView;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.model.data.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString * cellID = @"cell";
    [self.tableView registerClass:[PredetermineViewCell class] forCellReuseIdentifier:cellID];
    PredetermineViewCell * cell = [tableView dequeueReusableCellWithIdentifier:cellID forIndexPath:indexPath];
    if (!cell) {
        cell = [[PredetermineViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    cell.delegate = self;
    cell.modelData = self.model.data[indexPath.row];
//    cell.travelInfoBlock = ^(NSString * activityId){
//        ActivityDetailViewController * vc = [[ActivityDetailViewController alloc] init];
//        vc.activityId = [activityId intValue];
//        [self.navigationController pushViewController:vc animated:YES];
//    };
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 160;
}

- (void)evaluateBtnClickToNextPage{
    NSLog(@"立即评价页面");
    ImmediateEvaluationViewController * immediateVC = [[ImmediateEvaluationViewController alloc] init];
    [self.navigationController pushViewController:immediateVC animated:YES];
}

- (void)checkBtnClickToNextPage:(NSString *)listId{
    NSLog(@"查看预订单页面");
    OrderInformationViewController * orderInformationVC = [[OrderInformationViewController alloc] init];
    int orderId = [listId intValue];
    orderInformationVC.orderId = orderId;
    [self.navigationController pushViewController:orderInformationVC animated:YES];
}

@end
